package leetcode.code0962;

import java.util.Arrays;
import java.util.Stack;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution2 implements IDebug {
	public int maxWidthRamp(int[] nums) {
		int ans = 0;
		Integer[] idx = new Integer[nums.length];
		for (int i = 0; i < nums.length; i++) {
			idx[i] = i;
		}
		Arrays.sort(idx, (a, b) -> nums[a] - nums[b]);
		for (int i = 0 , min = Integer.MAX_VALUE; i < idx.length; i++) {
			min = Math.min(min, idx[i]);
			ans = Math.max(ans, idx[i] - min);
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(4, this.maxWidthRamp(H.str2array3("[6,0,8,2,1,5]")));
		H.compare(7, this.maxWidthRamp(H.str2array3("[9,8,1,0,1,9,4,0,4,1]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
